package com.bzchao.ds.core.config;

import com.bzchao.ds.core.dao.DataSourceDao;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 初始化数据库连接
 */
@Configuration
public class DataSourceInit implements InitializingBean {

    @Autowired
    private DynamicDataSource dynamicDataSource;
    @Resource
    private DataSourceDao dataSourceDao;

    @Override
    public void afterPropertiesSet() throws Exception {
        List<Map<String, String>> mapList = dataSourceDao.listEnableDataSource();
        dynamicDataSource.setDataSources(mapList);

    }
}
